<script setup>
// 从vue-router中引入链接组件 和目标容器承载组件
import { RouterLink, RouterView } from "vue-router";
import { onMounted } from "vue";

onMounted(() => {
   console.log("href", window.location.href);
});
</script>

<template>
   <!-- 组件切换转场动画名曰fade 模式=A先离场B再入场 -->
   <router-view v-slot="{ Component }">
      <transition
         name="slide-fade"
         mode="out-in">
         <component :is="Component"></component>
      </transition>
   </router-view>

   <!-- tabbar -->
   <footer>
      <!-- tabbar 当前路由的名字不为detail时显示tabbar -->
      <nav
         class="tab-wrapper"
         v-show="!$route.meta.hideTabBar">
         <!-- 点击跳转应用内路由 / -->
         <!-- 点击时本质切换的是组件 -->
         <!-- 目标组件会显示在RouterView中 -->
         <!-- RouterLink渲染完毕的最终结果是a标签 -->
         <!-- 点击链接的时候 跳转地址 地址对应的组件在路由表中 -->
         <RouterLink
            active-class="active"
            class="tab"
            :class="{ active: $route.path.startsWith('/film/') }"
            to="/film">
            <span><i class="fa fa-toggle-right"></i></span>
            <span>电影</span>
         </RouterLink>

         <RouterLink
            active-class="active"
            class="tab"
            to="/cinema">
            <span><i class="fa fa-bank"></i></span>
            <span>影院</span>
         </RouterLink>

         <RouterLink
            active-class="active"
            class="tab"
            to="/news">
            <span><i class="fa fa-volume-up"></i></span>
            <span>资讯</span>
         </RouterLink>

         <RouterLink
            active-class="active"
            class="tab"
            to="/mine">
            <span><i class="fa fa-user-circle"></i></span>
            <span>我的</span>
         </RouterLink>
      </nav>
   </footer>
</template>

<!-- 根组件的样式 scope=作用域 scoped=样式仅在当前组件中生效 -->
<style scoped>
footer {
   position: fixed;
   bottom: 0;
   width: 100%;
}

.tab-wrapper {
   display: flex;
   flex-direction: row;
   border-top: 1px solid #eee;
   background-color: white;
}

.tab {
   flex-grow: 1;
   height: 49px;
   display: flex;
   flex-direction: column;
   justify-content: center;
   text-decoration: none;
   font-size: 12px;
}

.tab.active > span,
.tab.active > span > i {
   color: #ff5f16;
}

.tab .fa {
   font-size: 20px;
}

.tab > span {
   display: flex;
   justify-content: center;
   align-items: center;
   color: #888;
}

/* 定义转场动画 */
.slide-fade-enter-active,
.slide-fade-leave-active {
   transition: all 0.5s ease;
}

/* [进来之前]与[离去之后]的状态 */
.slide-fade-enter-from,
.slide-fade-leave-to {
   opacity: 0;
   transform: translateY(20px);
}
</style>
